package com.jisf.driver.controller;

import com.jisf.driver.entity.po.StudentApply;
import com.jisf.driver.entity.vo.StudentApplyVo;
import com.jisf.driver.response.Result;
import com.jisf.driver.response.ResultCode;
import com.jisf.driver.service.IStudentApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jisf
 * @since 2022-05-23
 */
@RestController
@RequestMapping("/driver/studentApply")
public class StudentApplyController {

    @Autowired
    private IStudentApplyService iStudentApplyService;

    @GetMapping("apply")
    @PreAuthorize("hasAnyAuthority('studentApply:apply')")
    public Result<?> apply(@RequestParam Integer id){
        ResultCode resultCode = iStudentApplyService.apply(id);
        return Result.ok(resultCode);
    }

    @GetMapping("apply/list")
    @PreAuthorize("hasAnyAuthority('studentApply:apply:list')")
    public Result<?> applyList(){
        List<StudentApplyVo> studentApplyVos = iStudentApplyService.applyList();
        return Result.ok(studentApplyVos);
    }

    @PostMapping("pass/apply")
    @PreAuthorize("hasAnyAuthority('studentApply:pass:apply')")
    public Result<?> passApply(@RequestBody StudentApply studentApply){
        ResultCode resultCode = iStudentApplyService.passApply(studentApply);
        return Result.ok(resultCode);
    }

    @PostMapping("noPass/apply")
    @PreAuthorize("hasAnyAuthority('studentApply:noPass:apply')")
    public Result<?> noPassApply(@RequestBody StudentApply studentApply){
        ResultCode resultCode = iStudentApplyService.noPassApply(studentApply);
        return Result.ok(resultCode);
    }

}
